/**
 * @param {number[]} nums
 * @return {number}
 */
const mostFrequentEven = function(nums) {
    let count = new Map();
    for (let x of nums) {
        if (x % 2 === 0) {
            // count.add(num, count.get(num) + 1); 错
            count.set(x, (count.get(x) || 0 )+ 1);
        }

    }
    let res = -1, ct = 0;
    // let k, v in count.items() 错
    for (let [k, v] of count) {
        if (res === -1 || v > ct || v === ct && res > k) {
            res = k;
            ct = v;
        }
    }
    return res;
};

const nums = [0,1,2,2,4,4,1];
const expected = 2;

const ans = mostFrequentEven(nums);
console.log("ans: ", ans)
// expect 不可以用！
// expect(ans).toBe(expected);

module.exports = mostFrequentEven;